package com.ghostworks.galileo.watcher;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import twitter4j.*;

public class Initiate {
	public static void main(String[] args) {
//		WatcherData data = new WatcherData();
	//	ArrayList<String> lstTags = data.getTagsByUser("mugdho");
		//for (String strTags: lstTags) {????????????????????????????????????????"""
			//System.out.println(strTags);
		//}
		
		Initiate init = new Initiate();
		Watcher watcher = new Watcher("2ttw", "IndiaTamil");
		watcher.InitateWatch();
//		HashMap map = init.createTestMap();
//		WatcherData data = new WatcherData();
//		data.insertTags(map, "User1");
		
//		System.out.print(map);
	}
	private HashMap<Long, ArrayList<String>>createTestMap() {
		HashMap<Long, ArrayList<String>> hm = new HashMap<Long, ArrayList<String>>();
		ArrayList<String> lstMap = new ArrayList<String>();
		lstMap.add("Tag1");
		lstMap.add("Tag2");
		lstMap.add("Tag2");
		lstMap.add("Tag4");
		
		hm.put(new Long(1234), lstMap);
		hm.put(new Long(1233), lstMap);
		hm.put(new Long(1235), lstMap);
		hm.put(new Long(1236), lstMap);
		
		return hm;
	}
	public void getTweet() {
		try {
			Twitter twitter = new TwitterFactory().getInstance("mugdho", "aks4u1");
			List<Status> statuses = twitter.getFriendsTimeline();
			String strTweet = "";
			for (Status status: statuses) {
				strTweet = status.getText();
				
				System.out.println(status.getUser().getName() + ":" + status.getText() + ":" + status.getId());
			}
		} catch (Exception ex) {
		}

	}
	
	private HashMap locateTags() {
		String strTweet = "";
		String strTag = "";
		int intIndex = -1;
		/* HashMap to store tags linked at a TweetID level
		 * Here is an example
		 * TweetID 123456 has tags #Tag1 and #Tag2
		 * Therefore the HashMap will hold an ArrayList of tags 1 and 2 keyed with TweetID 
		 */
		HashMap<Long, ArrayList<String>> hmTweet = 
			new HashMap<Long, ArrayList<String>>();

		ArrayList<String> lstTags = null;
//		for (Status status: statuses) {
			strTweet = "This is a #tag#tag2 #tag3";
			lstTags = new ArrayList<String>();
		
			// Locate the # character in the current string
			intIndex = strTweet.indexOf(Constants.HASH);
			
			// This loop exists when no more indices are found for #
			while(intIndex > -1) {
				// Get the tag as the characters between the hash and the first space.
				if (strTweet.indexOf(Constants.SPACE, intIndex) > -1) {
					strTag =  strTweet.substring(intIndex, 
							strTweet.indexOf(Constants.SPACE, intIndex + 1)) ;
				} else {
					strTag =  strTweet.substring(intIndex, strTweet.length()); 
				}
				lstTags.add(strTag);
				// Get the next index.
				intIndex = strTweet.indexOf(Constants.HASH, intIndex+1);
			}

			// Since all the tags have been found add lstTags to hmTweet.
			hmTweet.put(new Long(123456), lstTags);
//		}
			return hmTweet;
	}
	
}